package com.contory.ssn_lgnd.app.maingame;

import java.util.ArrayList;

import android.util.Log;

import com.contory.ssn_lgnd.app.Assets;
import com.contory.ssn_lgnd.app.comp.ViewObject;
import com.contory.ssn_lgnd.framework.gl.SpriteBatcher;
import com.contory.ssn_lgnd.framework.gl.TextureRegion;
import com.contory.ssn_lgnd.framework.math.Polygon;
import com.contory.ssn_lgnd.framework.math.Vector2;

public class TerrainPartsRect extends TerrainParts{
	int wViewCellCount;
	int hViewCellCount;
	ViewObject[] rectView;
	Vector2 viewPos;
	
	public TerrainPartsRect(float strX, float strY, int w, int h){
		viewPos = new Vector2(strX, strY);
		
		wViewCellCount = w;
		hViewCellCount = h;
		
		coliBound = new Polygon();
		coliBound.lockAddPoint(wViewCellCount * TILE_WIDTH, hViewCellCount * TILE_HEIGHT);
		coliBound.addPoint(0, 0);
		coliBound.addPoint(1, 0);
		coliBound.addPoint(1, 1);
		coliBound.addPoint(0, 1);
		coliBound.unLockAddPoint();
		coliBound.setPos(strX + ((float)(wViewCellCount * TILE_WIDTH)/2 - TILE_WIDTH/2), 
				(float)strY - (hViewCellCount-1)*(TILE_HEIGHT/2));
		rectView = new ViewObject[w * h];
		for(int i = 0; i < rectView.length; i++)
			rectView[i] = new ViewObject();
		viewObjectInit();
	}
	
	private void viewObjectInit(){
		for(int i = 0; i < rectView.length; i++){
			rectView[i].setXY_WH_TR((float)((i % wViewCellCount) * 1.0f) + viewPos.x, 
					-(float)((i / wViewCellCount) * 1.0f) + viewPos.y, TILE_WIDTH, TILE_HEIGHT, Assets.TEX_REG_TERRAIN_RECTTILE);
		}
	}
	
	@Override
	public void draw(SpriteBatcher batcher) {
		for(int i = 0; i < rectView.length; i++)
		{
			batcher.drawSprite(rectView[i].x, rectView[i].y, rectView[i].w, rectView[i].h, rectView[i].tr);
		}
	}

	@Override
	public float getPosX() {
		return viewPos.x;
	}

	@Override
	public float getPosY() {
		return viewPos.y;
	}

	@Override
	public void setPos(float x, float y) {
		coliBound.setPos(x + ((float)(wViewCellCount * TILE_WIDTH)/2 - TILE_WIDTH/2), (float)y);
		viewPos.x = x;
		viewPos.y = y;
		viewObjectInit();
	}

	@Override
	public boolean getEnableBool() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void setEnable(boolean enalbeBool) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void setEnergy(int energy) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public int getEnergy() {
		// TODO Auto-generated method stub
		return 0;
	}
}
